<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="main" style="width: 600px;height:400px;"></div>

    <script src="./lib/echarts.min.js"></script>
    
    <script>
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));

        // 食物数据
        const foodArr = [
            { name: '西兰花', price: 150 },
            { name: '西瓜', price: 230 },
            { name: '西葫芦', price: 224 },
            { name: '西北风', price: 34 },
            { name: '西红柿', price: 135 },
            { name: '西芹', price: 147 },
            { name: '西洋菜', price: 260 },
        ]

        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '食物售价',
                textStyle: {
                    fontSize: 16,
                    // color:'#ff0000'
                },
                left: 5,
                top: 5
            },
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                right: 5,
                itemStyle: {
                    color: '#ff0000'
                },
                data: ['价格']
            },
            grid: {
                left: '20%'
            },
            xAxis: {
                data: foodArr.map(item => item.name)//['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
            },
            yAxis: {
                splitLine: {
                    lineStyle: {
                        type: 'dashed'
                    }
                }
            },
            series: [
                {
                    name: '价格',
                    type: 'bar',
                    colorBy: 'data',
                    data: foodArr.map(item => item.price) //[5, 20, 36, 10, 10, 20]
                }
            ],
            color: ['#ff0000', '#00ff00', '#0000ff']
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    </script>
</body>

</html>